#include "board.h"
#include "soft_timer.h"
#include "mlog.h"
#include "rtc_time.h"
#include "meter.h"


#define DEC2BCD(dec) (dec+(dec/10)*6)

#define BCD2DEC(bcd) (bcd-(bcd>>4)*6)

struct tm systemDataTime;

struct tm rtc_get_date_time(void)
{
  FL_RTC_InitTypeDef rtc_time;
	rtc_get_time(&rtc_time);
	
	systemDataTime.tm_year = 100 + BCD2DEC(rtc_time.year);
	systemDataTime.tm_mon = BCD2DEC(rtc_time.month);
	systemDataTime.tm_mday = BCD2DEC(rtc_time.day);
	systemDataTime.tm_hour = BCD2DEC(rtc_time.hour);
	systemDataTime.tm_min = BCD2DEC(rtc_time.minute);
	systemDataTime.tm_sec = BCD2DEC(rtc_time.second);
	systemDataTime.tm_isdst = -1;
  /*更新参数表区时间*/
  
  return systemDataTime;
}


/*获取RTC时间戳*/
uint32_t rtc_get_timestamps(void)
{
  rtc_get_date_time();
  return mktime(&systemDataTime);
}


void rtc_report_datetime(void)
{
	mprintf(LOG_INFO, "timestamps:%d.\r\n", rtc_get_timestamps());
	
	mprintf(LOG_INFO, "DATE TIME:%d-%d-%d %d:%d:%d.\r\n"
	, systemDataTime.tm_year + 1900
	, systemDataTime.tm_mon + 1
	, systemDataTime.tm_mday
	, systemDataTime.tm_hour
	, systemDataTime.tm_min
	, systemDataTime.tm_sec);
	
	
}

